package autopilot {	
	import flash.display.MovieClip;	
	import flash.display.StageAlign;	
	import flash.display.StageScaleMode;	
	import flash.events.Event;	
	import flash.net.navigateToURL;	
	
	import com.googlecode.milib.MILibMain;	
	import com.googlecode.milib.abstract.IMLBroadcastClassListener;	
	import com.googlecode.milib.display.button.views.ButtonViewFourFrames;	
	import com.googlecode.milib.display.service.MLButton;	
	import com.googlecode.milib.display.service.MLMC;	
	import com.googlecode.milib.vo.MLEventInfo;
	
	/**
	 * @author Marek Brun 'minim'
	 */
	public class AutopilotMain extends MovieClip implements IMLBroadcastClassListener {
		
		private var startPanel:Startpanel;				private var ogame:OGameAutopilot;				private var mc_game:MovieClip;		
		private var btnShowInBrowser:MLButton;		
		private var mainMC:MLMC;
		
		public function AutopilotMain() {
			//http://s11.ogame.onet.pl/game/index.php?page=b_building&session=**********&bau=1&cp=34722476
			//http://s11.ogame.onet.pl/game/reg/login2.php?v=2&universe=s11.ogame.onet.pl&login=******&pass=******&button.x=27&button.y=1			stage.scaleMode=StageScaleMode.NO_SCALE; 
			stage.align=StageAlign.TOP_LEFT;
						MILibMain.init(this);			ogame=new OGameAutopilot();			ogame.addListener(this);			addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0, true);
			
					}//<>
		
//********************************************************************************************
//		events for AutopilotMain
//********************************************************************************************
		public function onEvent(ev:MLEventInfo):void {			if(ev.contextID!=null){ return; }
			switch(ev.hero){
				case startPanel:
					switch(ev.event) {
						case startPanel.event_Start:							mainMC.mc.removeChild(startPanel.mc);
							ogame.start('s'+String(ev.data.u)+'.ogame.onet.pl', ev.data.login, ev.data.pass);
						break;
					}
				break;				case ogame:					switch(ev.event) {						case ogame.event_LoggingFail:							mainMC.mc.addChild(startPanel.mc);							mainMC.mc.removeChild(mc_game);						break;						case ogame.event_LoggingSuccesfull:							mainMC.mc.addChild(mc_game);						break;					}				break;
				case btnShowInBrowser:
					switch(ev.event) {
						case btnShowInBrowser.event_Press:
							navigateToURL(ogame.getGameURL());
						break;
					}
				break;
			}
		}//<<
		
		protected function onEnterFrame(event:Event):void {
			removeEventListener(Event.ENTER_FRAME, onEnterFrame);
			mainMC=MLMC.forInstance(MovieClip(getChildByName('a')));			mc_game=mainMC.getMC('game');
			startPanel=new Startpanel(mainMC.getMC('start'));
			startPanel.addListener(this);
			btnShowInBrowser=mainMC.getMLButton('game.btnShowInBrowser');
			btnShowInBrowser.addButtonView(ButtonViewFourFrames.forInstance(mainMC.getMC('game.btnShowInBrowser')));
			btnShowInBrowser.addListener(this);
			mainMC.mc.removeChild(mc_game);
		}//<<
		
	}
}
